package com.server.http.handler.impl;

import com.server.conditionenum.HttpReturnStatus;
import com.server.db.DataBaseManager;
import com.server.http.handler.HttpHandler;
import com.server.http.request.HttpRequestMessage;
import com.server.http.response.HttpResponseMessage;
import com.server.mine.net.HttpProtocol;

/**
* @author	李小布
* @email	397554852@qq.com
* @version	创建时间：2018年9月20日 下午4:23:56
*/
public class AddApp extends HttpHandler{
	@Override
	public void handle(HttpRequestMessage request, HttpResponseMessage response) {
		int status = 0;
		String failMsg = null;
		
		String appname = request.getParameter("appname");
		if(appname == null || appname == "" ) {
			failMsg = "参数错误或参数值为空！";
		}
		if(failMsg == null && DataBaseManager.GetInstance().AddApp(appname)) {
			status = 1;
		}else {
			failMsg = "app名字重复,请更换名字!";
		}
		if(status == 1) {
			SetReturnData(response,"创建成功",HttpProtocol.ADDAPP,HttpReturnStatus.Successed);
		}else {
			SetReturnData(response,failMsg,HttpProtocol.ADDAPP,HttpReturnStatus.Failed);
		}
	}
}